/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.hop.workflow.actions.actionplugins;

import org.apache.hop.core.variables.IVariables;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.ITransformDialog;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Shell;

/** This dialog allows you to edit a Action Abort object. */
public class ActionPluginsDialog extends BaseTransformDialog implements ITransformDialog {
  private static final Class<?> PKG = ActionPluginsDialog.class; // For Translator

  private final ActionPluginsMeta meta;

  private boolean changed;

  private Browser wBrowser;

  public ActionPluginsDialog(
      Shell parent, IVariables variables, Object in, PipelineMeta pipelineMeta, String sname) {
    super(parent, variables, (BaseTransformMeta) in, pipelineMeta, sname);
    meta = (ActionPluginsMeta) in;
  }

  @Override
  public String open() {
    Shell parent = getParent();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX | SWT.RESIZE);
    shell.setMinimumSize(400, 200);
    PropsUi.setLook(shell);
    shell.setLayout(new FormLayout());
    shell.setText("设置属性");
    // 计算屏幕尺寸并居中显示
    int screenWidth = parent.getBounds().width;
    int screenHeight = parent.getBounds().height;
    shell.setLocation(
        (screenWidth - shell.getBounds().width) / 2, (screenHeight - shell.getBounds().height) / 2);

    wBrowser = new Browser(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    FormData fdBrowser = new FormData();
    fdBrowser.left = new FormAttachment(0, 0);
    fdBrowser.top = new FormAttachment(0, 0);
    fdBrowser.right = new FormAttachment(100, 0);
    fdBrowser.bottom = new FormAttachment(100, 0);
    wBrowser.setLayoutData(fdBrowser);

    // JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    // executor.execute("alert");
    wBrowser.setUrl("./webpluginsdialog/ActionPlugins.html?tm=" + System.currentTimeMillis());

    shell.open();
    return transformName;
  }
}
